package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;

import java.util.List;

import flc.ast.BaseAc;
import flc.ast.HomeActivity;
import flc.ast.R;
import flc.ast.bean.MyAlbumBean;
import flc.ast.bean.MyAlbumItemBean;
import flc.ast.databinding.ActivityVideoDetailBinding;
import flc.ast.databinding.ActivityVideoRecordDetailBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.IntentUtil;

public class VideoDetailActivity extends BaseAc<ActivityVideoDetailBinding> {

    public static int selPosition;
    private String videoPath;

    @Override
    protected int onCreate() {
        return R.layout.activity_video_detail;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivVideoDetailBack.setOnClickListener(v -> onBackPressed());
        mDataBinding.ivVideoDetailImg.setOnClickListener(this);
        mDataBinding.tvDelete.setOnClickListener(this);
        mDataBinding.tvEdit.setOnClickListener(this);
        mDataBinding.tvShare.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivVideoDetailImg://播放
                PlayActivity.videoPath = videoPath;
                startActivity(PlayActivity.class);
                break;
            case R.id.tvDelete://删除
                delete();
                break;
            case R.id.tvEdit://编辑
                VideoEditActivity.mEditVideoPath = videoPath;
                startActivity(VideoEditActivity.class);
                break;
            case R.id.tvShare://分享
                share();
                break;
        }
    }

    @Override
    protected void initData() {
        videoPath = AlbumDetailActivity.myBean.getList().get(selPosition).getPath();
        Glide.with(mContext).load(videoPath).into(mDataBinding.ivVideoDetailImg);
    }

    //删除
    private void delete() {
        List<MyAlbumBean> listSp = AppSpUtils.getAlbumList();
        if (listSp != null && listSp.size() > 0) {
            for (MyAlbumBean bean : listSp) {
                if (bean.getId().equals(AlbumDetailActivity.myBean.getId())) {
                    bean.getList().remove(selPosition);
                    if (bean.getList().size() == 0) {
                        listSp.remove(bean);
                        startActivity(HomeActivity.class);
                    }
                    break;
                }
            }
            AppSpUtils.saveAlbumList(listSp);
            finish();
        }
    }

    //分享
    private void share() {
        IntentUtil.shareVideo(mContext, videoPath);
    }

}